home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / SETCOLOR.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  7KB  |  264 lines

  1. #include "pt.h" 
  2. #include "conio.h" 
  3. #include "string.h" 
  4.  
  5. void pascal
  6. /* XTAG:setColor */
  7. setColor(w)
  8.     register struct window *w;
  9. {
  10.     extern union REGS rin, rout;
  11.     extern unsigned char msgBuffer[];
  12.     extern struct window *selWindow;
  13.     extern long selBegin, selEnd;
  14.     extern unsigned char textColor, selColor;
  15.     extern unsigned char bannerColor, borderColor, elevColor;
  16.     extern unsigned char msgColor, promptColor, errorColor, topColor;
  17.     extern int scrRows, scrCols;
  18.     extern struct SREGS segRegs;
  19.     extern int debug;
  20.     
  21.     struct window *saveWindow;
  22.     long saveBegin, saveEnd, savePosTopline;
  23.     int saveRow1, saveCol1, saveRow2, saveCol2, saveNumTopline;
  24.     int row, col, background, foreground;
  25.     register int i;
  26.     int backStart, backStop;
  27.     unsigned char ch1, ch2, *line, *line1, *line2;
  28.     unsigned char saveTextColor, saveSelColor;
  29.     unsigned char saveBannerColor, saveBorderColor;
  30.     unsigned char saveElevColor, saveMsgColor;
  31.     unsigned char savePromptColor, saveErrorColor;
  32.     unsigned char saveTopColor, color, whichColor;
  33.  
  34.     /* initialize */
  35.     backStart = 0;
  36.     backStop = 8;
  37.     whichColor = 0;
  38.  
  39.     /* save the present state */
  40.     saveTextColor = w->textColor;
  41.     saveSelColor = w->selColor;
  42.     saveBannerColor = w->bannerColor;
  43.     saveBorderColor = w->borderColor;
  44.     saveElevColor = w->elevColor;
  45.     saveMsgColor = msgColor;
  46.     savePromptColor = promptColor;
  47.     saveErrorColor = errorColor;
  48.     saveTopColor = topColor;
  49.     
  50.     /* save stuff */
  51.     saveWindow = selWindow;
  52.     selWindow = w;
  53.     saveBegin = selBegin;
  54.     selBegin = 18;
  55.     saveEnd = selEnd;
  56.     selEnd = 55;
  57.     saveRow1 = w->row1;
  58.     w->row1 = 15;
  59.     saveCol1 = w->col1;
  60.     w->col1 = 20;
  61.     saveRow2 = w->row2;
  62.     w->row2 = scrRows-1;
  63.     saveCol2 = w->col2;
  64.     w->col2 = scrCols-2;
  65.     savePosTopline = w->posTopline;
  66.     w->posTopline = 0;
  67.     saveNumTopline = w->numTopline;
  68.     w->numTopline = 0;
  69.  
  70. restart:
  71.     /* set up the map and draw the menu */
  72.     setMap(0, 0, scrRows-1, scrCols-1, 2, 0x7);
  73.  
  74.     /* draw the color selections */
  75.     row = 6;
  76.     for(background = backStart; background < backStop; background++) {
  77.         col = 0;
  78.         for(foreground = 0; foreground < 16; foreground++) {
  79.             color = (unsigned char)(foreground + 16*background);
  80.             displayChar(row, col++, ' ', color);
  81.             if( background < 10 )
  82.                 ch1 = (unsigned char)'0'
  83.                         + (unsigned char)background;
  84.             else
  85.                 ch1 = (unsigned char)'A'
  86.                     + (unsigned char)background - 10;
  87.             displayChar(row, col++, ch1, color);
  88.             if( foreground < 10 )
  89.                 ch2 = (unsigned char)'0'
  90.                         + (unsigned char)foreground;
  91.             else
  92.                 ch2 = (unsigned char)'A'
  93.                     + (unsigned char)foreground - 10;
  94.             displayChar(row, col++, ch2, color);
  95.             displayChar(row, col++, ' ', color);
  96.             col++;
  97.         }
  98.         ++row;
  99.     }
  100.  
  101.     /* display the instructions */
  102.     line =
  103. "         SELECT a display part to change the color of or EXIT to Point";
  104.     for(i = 0; line[i] != '\0'; i++)
  105.         displayChar(0, i, line[i], msgColor);
  106.  
  107.     line =
  108. "SHOW plain/alternate color menus or CHANGE alternate colors are intense/blinking";
  109.     for(i = 0; line[i] != '\0'; i++)
  110.         displayChar(3, i, line[i], msgColor);
  111.  
  112.     line =
  113. "      CLICK on a foreground/background color for the selected display part";
  114.     for(i = 0; line[i] != '\0'; i++)
  115.         displayChar(5, i, line[i], msgColor);
  116.  
  117.     line =
  118.  "  Show-Plain-Colors    Show-Alt-Colors   Intense-Alt-Colors  Blinking-Alt-Colors";
  119.     for(i = 0; line[i] != '\0'; i++)
  120.         displayChar(4, i, line[i], textColor);
  121.  
  122.     line1 =
  123.  "      Text          Selection        Banner          Border         Elevator    ";
  124.  
  125.     line2 =
  126.  "    Info Msgs      User Input      Error Msgs       Top Line          Exit      ";
  127.     while( 1 ) {
  128.  
  129.         /* draw the sample window */
  130.         setMap(0, 0, scrRows-1, scrCols-1, 1, 0);
  131.         drawWindow(w);
  132.  
  133.         /* draw the message things */
  134.         line = "  Info Msgs   ";
  135.         for(i = 0; line[i] != '\0'; i++)
  136.             displayChar(17, i, line[i], msgColor);
  137.         line = "  User Input  ";
  138.         for(i = 0; line[i] != '\0'; i++)
  139.             displayChar(19, i, line[i], promptColor);
  140.         line = "  Error Msgs  ";
  141.         for(i = 0; line[i] != '\0'; i++)
  142.             displayChar(21, i, line[i], errorColor);
  143.         line = "  Top Line    ";
  144.         for(i = 0; line[i] != '\0'; i++)
  145.             displayChar(23, i, line[i], topColor);
  146.  
  147.         /* draw in the two menu lines that can be selected in */
  148.         for(i = 0; line1[i] != '\0'; i++) {
  149.             if( (i/16) == whichColor )
  150.                 color = selColor;
  151.             else
  152.                 color = textColor;
  153.             displayChar(1, i, line1[i], color);
  154.         }
  155.         for(i = 0; line2[i] != '\0'; i++) {
  156.             if( (i/16+5) == whichColor )
  157.                 color = selColor;
  158.             else
  159.                 color = textColor;
  160.             displayChar(2, i, line2[i], color);
  161.         }
  162.         updateScreen(0, scrRows-1);
  163.  
  164.         /* wait for a mouse button press and release and act on it */
  165.         if( downButtons(&row, &col) ) {    /* ESCape key */
  166.         restoreOriginalState:
  167.             /* restore the original state */
  168.             w->textColor = saveTextColor;
  169.             w->selColor = saveSelColor;
  170.             w->bannerColor = saveBannerColor;
  171.             w->borderColor = saveBorderColor;
  172.             w->elevColor = saveElevColor;
  173.             msgColor = saveMsgColor;
  174.             promptColor = savePromptColor;
  175.             errorColor = saveErrorColor;
  176.             topColor = saveTopColor;
  177.             goto quit;
  178.         }
  179.         up2Buttons(&row, &col);
  180.         switch( row ) {
  181.         case 0:    /* message lines so ignore the click */
  182.             goto quit;
  183.         case 3:
  184.         case 5:
  185.             break;
  186.         case 1:
  187.             whichColor = (unsigned char)(col/16);
  188.             break;
  189.         case 2:
  190.             whichColor = (unsigned char)(col/16 + 5);
  191.             if( whichColor > 8 )
  192.                 goto quit;
  193.             break;
  194.         case 4:
  195.             i = col/20;
  196.             switch( i ) {
  197.             case 0:
  198.                 backStart = 0;
  199.                 backStop = 8;
  200.                 break;
  201.             case 1:
  202.                 backStart = 8;
  203.                 backStop = 16;
  204.                 break;
  205.             case 2:
  206.             case 3:
  207.                 /* toggle intensity and blinking */
  208.  
  209.                 /* first for the enhanced graphics adapter */
  210.                 rin.h.ah = 0x10;
  211.                 rin.h.al = 3;
  212.                 rin.h.bl = (char)(i-2);
  213.                 int86(0x10, &rin, &rout);
  214.  
  215.                 /* now for the color graphics adapter */
  216.                 /* set the blinking bit */
  217.                 movedata(0x40, 0x65, segRegs.ds,
  218.                     (unsigned int)&ch2, 1);
  219.                 if( i == 2 ) {
  220.                     /* turn off blinking (intense on) */
  221.                     ch2 &= ~0x20;
  222.                 } else {
  223.                     ch2 |= 0x20; /* turn on blinking */
  224.                 }
  225.                 outp(0x3D8, ch2);
  226.                 break;
  227.             default:
  228.                 break;
  229.             }
  230.             goto restart;
  231.         default:
  232.             if( row > 23 )    /* bottom line? */
  233.                 goto restoreOriginalState;
  234.             if( row > 13 )    /* past color menu? */
  235.                 break;
  236.             color = (unsigned char)(16*(row-6+backStart) + col/5);
  237.             switch( whichColor ) {
  238.                 case 0: w->textColor = color; break;
  239.                 case 1: w->selColor = color; break;
  240.                 case 2: w->bannerColor = color; break;
  241.                 case 3: w->borderColor = color; break;
  242.                 case 4: w->elevColor = color; break;
  243.                 case 5: msgColor = color; break;
  244.                 case 6: promptColor = color; break;
  245.                 case 7: errorColor = color; break;
  246.                 case 8: topColor = color; break;
  247.             }
  248.             break;
  249.         }
  250.     }
  251.  
  252. quit:
  253.     /* restore stuff */
  254.     selWindow = saveWindow;
  255.     selBegin = saveBegin;
  256.     selEnd = saveEnd;
  257.     w->row1 = saveRow1;
  258.     w->col1 = saveCol1;
  259.     w->row2 = saveRow2;
  260.     w->col2 = saveCol2;
  261.     w->posTopline = savePosTopline;
  262.     w->numTopline = saveNumTopline;
  263. }
  264.